package com.luyu.datapermission;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;



@Service
@Slf4j
public class FieldDataPermissionSqlImpl {

    private HashMap<String, FieldDataPermissionService> map=new HashMap<>();

    @Autowired
    public void setMap(List<FieldDataPermissionService> serviceList) {
        serviceList.stream().forEach(item->{
            map.put(item.supportFiled(),item);
        });
    }

    public String getConditionSql(List<String> filedNameList){
        String strSql="";
        for (String filed : filedNameList) {
            FieldDataPermissionService service = map.get(filed);
            if ( service!= null && service.shouldAdd()) {
                strSql+= service.getSql();
            }else {
                log.info("字段{}不存在数据权限服务类，",filed);
            }
        }
        return strSql;
    }

}
